import request from '../utils/request'

export const commonApi = {
  /**
   * 获取启动信息
   */
  getBootstrppers(): Promise<Record<string, any>> {
    return request.get('/bootstrappers')
  },

  /**
   * 获取可用于打赏的礼物列表
   */
  getRewardGiftList(): Promise<DomoRewardGift[]> {
    return request.get('/reward-gifts')
  },

  /**
   * 举报内容
   */
  reportContent(type: ReportType, id: number, reason: string): Promise<void> {
    const apiMap = {
      feed: (id: number) => `/feeds/${id}/reports`,
      topic: (id: number) => `/user/report-feed-topics/${id}`,
      user: (id: number) => `/report/users/${id}`,
      comment: (id: number) => `/report/comments/${id}`,
      knowledge: (id: number) => `/knowledge/${id}/reports`,
      chapters: (id: number) => `/knowledge/chapters/${id}/reports`,
      info: (id: number) => `/infos/${id}/reports`,
      commodities: (id: number) => `/mall/commodities/${id}/report`,
      wendas: (id: number) => `/wendas/${id}/reports`,
      theme: (id: number) => `/feed-themes-report/${id}`,
      activity: (id: number) => `/user/events/${id}`,
    }
    const url = apiMap[type](id)
    if (type === 'topic' || type === 'activity') return request.put(url, { message: reason })
    return request.post(url, { reason })
  },
  /** 获取广告位 */
  getAdvertisingspace() {
    return request.get('/advertisingspace')
  },
  /** 批量获取广告列表 */
  getAdvertisingList(params: { space: string }) {
    return request.get('/advertisingspace/advertising', { params })
  },
  /** 生成二维码 */
  getQRCode(code: any) {
    return request.get(
      `/wechat/mini-program/wxacodeunlimit?params=${encodeURIComponent(
        JSON.stringify({ scene: code }),
      )}`,
      { header: { 'content-type': 'image / png' } },
    )
  },
  /** 获取热门城市 */
  getHotCity() {
    return request.get('/locations/hots')
  },
  /** 搜索城市 */
  getCity(params = { name: '' as string }) {
    return request.get('/locations/search', { params })
  },
  /** 获取话题权限 */
  getThemeConfig(): Promise<{}> {
    return request.get('/theme-config')
  },
}
